home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / ninjakd2.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  26KB  |  804 lines

  1. /***************************************************************************
  2.  
  3.  *****************************
  4.  *** NINJA KID II hardware ***        (by Roberto Ventura)
  5.  *****************************
  6.  
  7. Game authors:
  8. Game design:    Tsutomu Fuzisawa
  9. Program design: Satoru Kinjo
  10. Char. design:   Tsutomu Fizisawa
  11. Char. design:   Akemi Tsunoda
  12. Sound compose:  Tsutomu Fuzisawa
  13. Bgm create:     Mecano Associate
  14. Data make:      Takashi Hayashi
  15.  
  16. General aspect.
  17.  
  18. The game is driven by a fast Z80 CPU.
  19. Screen resolution is 256x192.
  20. 768 colors on screen.
  21. 96 sprites.
  22.  
  23. Rom Contents:
  24.  
  25. NK2_01.ROM              Main CPU program ROM
  26. NK2_02.ROM              CPU banked data ROM 0 (banks 0 and 1)
  27. NK2_03.ROM              CPU banked data ROM 1 (banks 2 and 3)
  28. NK2_04.ROM              CPU banked data ROM 2 (banks 4 and 5)
  29. NK2_05.ROM              CPU banked data ROM 3 (banks 6 and 7)
  30. NK2_06.ROM              Sound CPU program ROM (encrypted)
  31. NK2_07.ROM              Sprites data ROM 1
  32. NK2_08.ROM              Sprites data ROM 0
  33. NK2_09.ROM              Raw PCM samples (complete?)
  34. NK2_10.ROM              Background data ROM 1
  35. NK2_11.ROM              Background data ROM 0
  36. NK2_12.ROM              Foreground data ROM
  37.  
  38. *** MEMORY MAP ***
  39.  
  40. 0000-7fff       Main CPU ROM
  41. 8000-bfff       Banked CPU ROM
  42. c000-c7ff       I/O
  43. c800-cdff       Color RAM
  44. d000-d7ff       "FRONT" tile map
  45. d800-dfff       "BACK" tile map
  46. e000-efff       Main RAM
  47. f400-f7ff    ??? screen frame ???
  48. f800-f9ff    CPU Stack
  49. fa00-ffff       Sprite registers (misc RAM)
  50.  
  51.  
  52. 1) CPU
  53.  
  54. 1 OSC 12 Mhz
  55. 1 OSC 5 Mhz
  56. 2 YM 2203C.......CaBBe!.
  57.  
  58. The Z80 runs in IM0,the game expects execution of RST10 each
  59. frame.
  60.  
  61. Game level maps,additional code and data are available to main
  62. program via CPU banking at lacations 8000-bf00
  63.  
  64. The encryption scheme for ROM 6(alternate version) is very simple,
  65. I was surprised by such a large ROM (64k) for sound.
  66. The first half contains opcodes only (see machine 1 pin)
  67. while the second 32k chunk is for immediate data.
  68. Opcode and Data keep their relative positions as well.
  69.  
  70.  
  71.  
  72. 2) I/O
  73.  
  74. c000    "KEYCOIN" button
  75.  
  76.         76543210
  77.         || |  ||
  78.         || |  |^-COIN 1
  79.         || |  ^--COIN 2
  80.         || ^-----TEST MODE (on the fly,to be pressed during boot)
  81.         |^-------START 1
  82.         ^--------START 2
  83.  
  84.  
  85. c001    "PAD1"
  86. c002    "PAD2"
  87.  
  88.         76543210
  89.           ||||||
  90.           |||||^-RIGHT
  91.           ||||^--LEFT
  92.           |||^---DOWN
  93.           ||^----UP
  94.           |^-----FIRE 0
  95.           ^------FIRE 1
  96.  
  97.  
  98. c003    "DIPSW1"
  99.  
  100.         76543210
  101.         ||||||||
  102.         |||||||^-UNUSED?
  103.         ||||||^-->EXTRA
  104.         |||||^--->LIVES
  105.         ||||^----CONTINUE MODE
  106.         |||^-----DEMO SOUND
  107.         ||^------NORMAL/HARD
  108.         |^-------LIVES 3/4
  109.         ^--------ENGLISH/JAP
  110.  
  111.  
  112. c004    "DIPSW2"
  113.  
  114.         76543210
  115.         ||||||||
  116.         |||||||^-TEST MODE
  117.         ||||||^--TABLE/UPRIGHT
  118.         |||||^---"CREDIT SERVICE"
  119.         ||||^---->
  120.         |||^----->>
  121.         ||^------>>> coin/credit configurations
  122.         |^------->>
  123.         ^-------->
  124.  
  125. c200    Sound command?
  126.     This byte is written when game plays sound effects...
  127.     it is set when music or sound effects (both pcm and fm) are triggered;
  128.     I guess it is read by another CPU,then.
  129.  
  130. c201    Unknown,but used.
  131.  
  132. c202    Bank selector (0 to 7)
  133.  
  134. c203    Sprite 'overdraw'
  135.         this is the most interesting feature of the game,when set
  136.         the sprites drawn in the previous frame remain on the
  137.         screen,so the game can perform special effects such as the
  138.         'close up' when you die or the "infinite balls" appearing
  139.         when an extra weapon is collected.
  140.         Appears to work like a xor mask,a sprite removes older
  141.         sprite 'bitmap' when present;other memory locations connected to
  142.     this function may be f400-f7ff...should be investigated more.
  143.         -mmmh... I believe this is sci-fiction for a non-bitmap game...
  144.  
  145. C208    Scroll X  0-7
  146.  
  147. C209    Scroll X  MSB
  148.  
  149. C20A    Scroll Y  0-7
  150.  
  151. C20B    Scroll Y  MSB
  152.  
  153. C20C    Background ENABLE
  154.         when set to zero the background is totally black,but
  155.         sprites are drawn correctly.
  156.  
  157.  
  158. 3) COLOR RAM
  159.  
  160. The palette system is dynamic,the game can show up to 768 different
  161. colors on screen.
  162.  
  163. Palette depth is 12 bits as usual,two consecutive bytes are used for each
  164. color code.
  165.  
  166. format: RRRRGGGGBBBB0000
  167.  
  168. Colors are organized in palettes,since graphics is 4 bits (16 colors)
  169. each palette takes 32 bytes,the three different layers,BACK,SPRITES and
  170. FRONT don't share any color,each has its own 256 color space,hence the
  171. 768 colors on screen.
  172.  
  173. c800-c9ff       Background palettes
  174. ca00-cbff       Sprites palettes
  175. cc00-cdff       Foreground palettes
  176.  
  177.  
  178. 4) TILE-BASED LAYERS
  179.  
  180. The tile format for background and foreground is the same,the
  181. only difference is that background tiles are 16x16 pixels while foreground
  182. tiles are only 8x8.
  183.  
  184. Background virtual screen is 512x512 pixels scrollable.
  185.  
  186. Two consecutive tiles bytes identify one tile.
  187.  
  188.         O7 O6 O5 O4 O3 O2 O1 O0         gfx Offset
  189.         O9 O8 FY FX C3 C2 C1 C0         Attibute
  190.  
  191.         O= GFX offset (1024 tiles)
  192.         F= Flip X and Y
  193.         C= Color palette selector
  194.  
  195.  
  196. 5) SPRITES
  197.  
  198. Five bytes identify each sprite,but the registers actually used
  199. are placed at intervals of 16.
  200. Some of the remaining bytes are used (e.g. fa00),their meaning is totally
  201. unknown to me,they seem to be related to the surprising additional sprite
  202. feature of the game,but maybe they're just random writes in RAM.
  203.  
  204. The first sprite data is located at fa0b,then fa1b and so on.
  205.  
  206.  
  207. 0b      Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0         Y coord
  208. 0c      X7 X6 X5 X4 X3 X2 X1 X0         X coord
  209. 0d      O9 O8 FY FX -- -- EN X8         hi gfx - FLIP - Enable - hi X
  210. 0e      O7 O6 O5 O4 O3 O2 O1 O0         gfx - offset
  211. 0f      -- -- -- -- C3 C2 C1 C0         color
  212.  
  213.         Y= Y coordinate
  214.         X= X coordinate (X8 is used to clip sprite on the left)
  215.         O= Gfx offset (1024 sprites)
  216.         F= Flip
  217.        EN= Enable (this is maybe the Y8 coordinate bit,but it isn't set
  218.            accordingly in the test mode
  219.         C= Color palette selector
  220.  
  221. ***************************************************************************/
  222.  
  223.  
  224. #include "driver.h"
  225. #include "vidhrdw/generic.h"
  226.  
  227. WRITE_HANDLER( ninjakd2_bgvideoram_w );
  228. WRITE_HANDLER( ninjakd2_fgvideoram_w );
  229. WRITE_HANDLER( ninjakd2_sprite_overdraw_w );
  230. WRITE_HANDLER( ninjakd2_background_enable_w );
  231. int  ninjakd2_vh_start(void);
  232. void ninjakd2_vh_stop(void);
  233. void ninjakd2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  234.  
  235. extern unsigned char     *ninjakd2_scrolly_ram;
  236. extern unsigned char     *ninjakd2_scrollx_ram;
  237. extern unsigned char     *ninjakd2_bgenable_ram;
  238. extern unsigned char     *ninjakd2_spoverdraw_ram;
  239. extern unsigned char     *ninjakd2_spriteram;
  240. extern unsigned char     *ninjakd2_background_videoram;
  241. extern unsigned char     *ninjakd2_foreground_videoram;
  242. extern size_t ninjakd2_spriteram_size;
  243. extern size_t ninjakd2_backgroundram_size;
  244. extern size_t ninjakd2_foregroundram_size;
  245.  
  246. static int ninjakd2_bank_latch = 255;
  247.  
  248.  
  249.  
  250. int ninjakd2_init_samples(const struct MachineSound *msound)
  251. {
  252.     int i,n;
  253.     unsigned char *source = memory_region(REGION_SOUND1);
  254.     struct GameSamples *samples;
  255.     int sample_info [9][2] = { {0x0000,0x0A00},{0x0A00,0x1D00},{0x2700,0x1700},
  256.     {0x3E00,0x1500},{0x5300,0x0B00},{0x5E00,0x0A00},{0x6800,0x0E00},{0x7600,0x1E00},{0xF000,0x0400} };
  257.  
  258.     if ((Machine->samples = malloc(sizeof(struct GameSamples) + 9 * sizeof(struct GameSample *))) == NULL)
  259.         return 1;
  260.  
  261.     samples = Machine->samples;
  262.     samples->total = 8;
  263.  
  264.     for (i=0;i<8;i++)
  265.     {
  266.         if ((samples->sample[i] = malloc(sizeof(struct GameSample) + (sample_info[i][1]))) == NULL)
  267.             return 1;
  268.  
  269.         samples->sample[i]->length = sample_info[i][1];
  270.         samples->sample[i]->smpfreq = 16000;    /* 16 kHz */
  271.         samples->sample[i]->resolution = 8;
  272.         for (n=0; n<sample_info[i][1]; n++)
  273.             samples->sample[i]->data[n] = source[sample_info[i][0]+n] ^ 0x80;
  274.     }
  275.  
  276.     /*    The samples are now ready to be used.  They are a 8 bit, 16 khz samples.      */
  277.  
  278.     return 0;
  279. }
  280.  
  281.  
  282. int ninjakd2_interrupt(void)
  283. {
  284.     return 0x00d7;    /* RST 10h */
  285. }
  286.  
  287. READ_HANDLER( ninjakd2_bankselect_r )
  288. {
  289.     return ninjakd2_bank_latch;
  290. }
  291.  
  292. WRITE_HANDLER( ninjakd2_bankselect_w )
  293. {
  294.     unsigned char *RAM = memory_region(REGION_CPU1);
  295.     int bankaddress;
  296.  
  297.     if (data != ninjakd2_bank_latch)
  298.     {
  299.         ninjakd2_bank_latch = data;
  300.  
  301.         bankaddress = 0x10000 + ((data & 0x7) * 0x4000);
  302.         cpu_setbank(1,&RAM[bankaddress]);     /* Select 8 banks of 16k */
  303.     }
  304. }
  305.  
  306. WRITE_HANDLER( ninjakd2_pcm_play_w )
  307. {
  308.     int i;
  309.     int sample_no[9] = { 0x00,0x0A,0x27,0x3E,0x53,0x5E,0x68,0x76,0xF0 };
  310.  
  311.     for(i=0;i<9;i++)
  312.      if (sample_no[i]==data) break;
  313.  
  314.     if (i==8)
  315.         sample_stop(0);
  316.     else
  317.         sample_start(0,i,0);
  318. }
  319.  
  320. static struct MemoryReadAddress readmem[] =
  321. {
  322.     { 0x0000, 0x7fff, MRA_ROM },
  323.     { 0x8000, 0xbfff, MRA_BANK1 },
  324.     { 0xc000, 0xc000, input_port_2_r },
  325.     { 0xc001, 0xc001, input_port_0_r },
  326.     { 0xc002, 0xc002, input_port_1_r },
  327.     { 0xc003, 0xc003, input_port_3_r },
  328.     { 0xc004, 0xc004, input_port_4_r },
  329.     { 0xc200, 0xc200, MRA_RAM },
  330.     { 0xc201, 0xc201, MRA_RAM },        // unknown but used
  331.     { 0xc202, 0xc202, ninjakd2_bankselect_r },
  332.     { 0xc203, 0xc203, MRA_RAM },
  333.     { 0xc208, 0xc209, MRA_RAM },
  334.     { 0xc20a, 0xc20b, MRA_RAM },
  335.     { 0xc20c, 0xc20c, MRA_RAM },
  336.     { 0xc800, 0xffff, MRA_RAM },
  337.     { -1 }    /* end of table */
  338. };
  339.  
  340.  
  341. static struct MemoryWriteAddress writemem[] =
  342. {
  343.     { 0x0000, 0xbfff, MWA_ROM },
  344.     { 0xc200, 0xc200, soundlatch_w },
  345.     { 0xc201, 0xc201, MWA_RAM },        // unknown but used
  346.     { 0xc202, 0xc202, ninjakd2_bankselect_w },
  347.     { 0xc203, 0xc203, ninjakd2_sprite_overdraw_w, &ninjakd2_spoverdraw_ram },
  348.     { 0xc208, 0xc209, MWA_RAM, &ninjakd2_scrollx_ram },
  349.     { 0xc20a, 0xc20b, MWA_RAM, &ninjakd2_scrolly_ram },
  350.     { 0xc20c, 0xc20c, ninjakd2_background_enable_w, &ninjakd2_bgenable_ram },
  351.     { 0xc800, 0xcdff, paletteram_RRRRGGGGBBBBxxxx_swap_w, &paletteram },
  352.     { 0xd000, 0xd7ff, ninjakd2_fgvideoram_w, &ninjakd2_foreground_videoram, &ninjakd2_foregroundram_size },
  353.     { 0xd800, 0xdfff, ninjakd2_bgvideoram_w, &ninjakd2_background_videoram, &ninjakd2_backgroundram_size },
  354.     { 0xe000, 0xf9ff, MWA_RAM },
  355.     { 0xfa00, 0xffff, MWA_RAM, &ninjakd2_spriteram, &ninjakd2_spriteram_size },
  356.     { -1 }    /* end of table */
  357. };
  358.  
  359.  
  360. static struct MemoryReadAddress snd_readmem[] =
  361. {
  362.     { 0x0000, 0xbfff, MRA_ROM },
  363.     { 0xc000, 0xc7ff, MRA_RAM },
  364.     { 0xe000, 0xe000, soundlatch_r },
  365.     { 0xefee, 0xefee, MRA_NOP },
  366.     { -1 }    /* end of table */
  367. };
  368.  
  369.  
  370. static struct MemoryWriteAddress snd_writemem[] =
  371. {
  372.     { 0x0000, 0xbfff, MWA_ROM },
  373.     { 0xc000, 0xc7ff, MWA_RAM },
  374.     { 0xf000, 0xf000, ninjakd2_pcm_play_w },    /* PCM SAMPLE OFFSET*256 */
  375.     { 0xeff5, 0xeff6, MWA_NOP },            /* SAMPLE FREQUENCY ??? */
  376.     { 0xefee, 0xefee, MWA_NOP },            /* CHIP COMMAND ?? */
  377.     { -1 }    /* end of table */
  378. };
  379.  
  380. static struct IOWritePort snd_writeport[] =
  381. {
  382.     { 0x0000, 0x0000, YM2203_control_port_0_w },
  383.     { 0x0001, 0x0001, YM2203_write_port_0_w },
  384.     { 0x0080, 0x0080, YM2203_control_port_1_w },
  385.     { 0x0081, 0x0081, YM2203_write_port_1_w },
  386.     { -1 }    /* end of table */
  387. };
  388.  
  389.  
  390.  
  391. INPUT_PORTS_START( ninjakd2 )
  392.     PORT_START
  393.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
  394.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
  395.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
  396.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
  397.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
  398.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
  399.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  400.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  401.  
  402.     PORT_START    /* player 2 controls */
  403.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_COCKTAIL )
  404.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_COCKTAIL )
  405.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_COCKTAIL )
  406.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_COCKTAIL )
  407.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL )
  408.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_COCKTAIL )
  409.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  410.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  411.  
  412.     PORT_START
  413.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
  414.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
  415.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
  416.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
  417.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE )    /* keep pressed during boot to enter service mode */
  418.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
  419.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
  420.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
  421.  
  422.     PORT_START  /* dsw0 */
  423.     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
  424.     PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
  425.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  426.     PORT_DIPNAME( 0x06, 0x06, DEF_STR( Bonus_Life ) )
  427.     PORT_DIPSETTING(    0x04, "20000 50000" )
  428.     PORT_DIPSETTING(    0x06, "30000 50000" )
  429.     PORT_DIPSETTING(    0x02, "50000 100000" )
  430.     PORT_DIPSETTING(    0x00, "None" )
  431.     PORT_DIPNAME( 0x08, 0x08, "Allow Continue" )
  432.     PORT_DIPSETTING(    0x00, DEF_STR( No ) )
  433.     PORT_DIPSETTING(    0x08, DEF_STR( Yes )  )
  434.     PORT_DIPNAME( 0x10, 0x00, DEF_STR( Demo_Sounds ) )
  435.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  436.     PORT_DIPSETTING(    0x00, DEF_STR( On )  )
  437.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Difficulty ) )
  438.     PORT_DIPSETTING(    0x20, "Normal" )
  439.     PORT_DIPSETTING(    0x00, "Hard" )
  440.     PORT_DIPNAME( 0x40, 0x40, DEF_STR( Lives ) )
  441.     PORT_DIPSETTING(    0x40, "3" )
  442.     PORT_DIPSETTING(    0x00, "4" )
  443.     PORT_DIPNAME( 0x80, 0x00, "Language" )
  444.     PORT_DIPSETTING(    0x00, "English" )
  445.     PORT_DIPSETTING(    0x80, "Japanese" )
  446.  
  447.     PORT_START  /* dsw1 */
  448.     PORT_SERVICE( 0x01, IP_ACTIVE_LOW )
  449.     PORT_DIPNAME( 0x02, 0x00, DEF_STR( Cabinet ) )
  450.     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
  451.     PORT_DIPSETTING(    0x02, DEF_STR( Cocktail ) )
  452.     PORT_DIPNAME( 0x04, 0x00, "Credit Service" )
  453.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  454.     PORT_DIPSETTING(    0x04, DEF_STR( On ) )
  455.     PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) )
  456.     PORT_DIPSETTING(    0x00, DEF_STR( 2C_1C ) )
  457.     PORT_DIPSETTING(    0x18, DEF_STR( 1C_1C ) )
  458.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_2C ) )
  459.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_3C ) )
  460.     PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) )
  461.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  462.     PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
  463.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_1C ) )
  464.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_1C ) )
  465.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_1C ) )
  466.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_2C ) )
  467.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_3C ) )
  468.     PORT_DIPSETTING(    0x80, DEF_STR( 1C_4C ) )
  469. INPUT_PORTS_END
  470.  
  471.  
  472.  
  473. static struct GfxLayout charlayout =
  474. {
  475.     8,8,     /* 8*8 characters */
  476.     1024,    /* 1024 characters */
  477.     4,       /* 4 bits per pixel */
  478.     {0,1,2,3 }, /* the bitplanes are packed in one nibble */
  479.     {0, 4, 16384*8+0, 16384*8+4, 8, 12, 16384*8+8, 16384*8+12 },
  480.     {16*0, 16*1, 16*2, 16*3, 16*4, 16*5, 16*6, 16*7 },
  481.     8*16
  482. };
  483.  
  484. static struct GfxLayout spritelayout =
  485. {
  486.     16,16,   /* 16*16 characters */
  487.     1024,    /* 1024 sprites */
  488.     4,       /* 4 bits per pixel */
  489.     {0,1,2,3}, /* the bitplanes are packed in one nibble */
  490.     {0,  4,  65536*8+0,  65536*8+4,  8, 12,  65536*8+8, 65536*8+12,
  491.         16*8+0, 16*8+4, 16*8+65536*8+0, 16*8+65536*8+4, 16*8+8, 16*8+12, 16*8+65536*8+8, 16*8+65536*8+12},
  492.     {16*0, 16*1, 16*2, 16*3, 16*4, 16*5, 16*6, 16*7,
  493.         32*8+16*0, 32*8+16*1, 32*8+16*2, 32*8+16*3, 32*8+16*4, 32*8+16*5, 32*8+16*6, 32*8+16*7},
  494.     8*64
  495. };
  496.  
  497. static struct GfxDecodeInfo gfxdecodeinfo[] =
  498. {
  499.     { REGION_GFX1, 0, &spritelayout,  0*16, 16 },
  500.     { REGION_GFX2, 0, &spritelayout, 16*16, 16 },
  501.     { REGION_GFX3, 0, &charlayout,   32*16, 16 },
  502.     { -1 } /* end of array */
  503. };
  504.  
  505. static struct Samplesinterface samples_interface =
  506. {
  507.     1,    /* 1 channel */
  508.     25    /* volume */
  509. };
  510.  
  511. static struct CustomSound_interface custom_interface =
  512. {
  513.     ninjakd2_init_samples,
  514.     0,
  515.     0
  516. };
  517.  
  518. /* handler called by the 2203 emulator when the internal timers cause an IRQ */
  519. static void irqhandler(int irq)
  520. {
  521.     cpu_set_irq_line(1,0,irq ? ASSERT_LINE : CLEAR_LINE);
  522. }
  523.  
  524. static struct YM2203interface ym2203_interface =
  525. {
  526.     2,      /* 2 chips */
  527.     1500000, /* 12000000/8 MHz */
  528.     { YM2203_VOL(25,25), YM2203_VOL(25,25) },
  529.     { 0 },
  530.     { 0 },
  531.     { 0 },
  532.     { 0 },
  533.     { irqhandler }
  534. };
  535.  
  536.  
  537. static struct MachineDriver machine_driver_ninjakd2 =
  538. {
  539.     {
  540.         {
  541.             CPU_Z80,
  542.             6000000,        /* 12000000/2 ??? */
  543.             readmem,writemem,0,0,    /* very sensitive to these settings */
  544.             ninjakd2_interrupt,1
  545.         }
  546.     },
  547.     60, 10000,            /* frames per second, vblank duration */
  548.     10,                /* single CPU, no need for interleaving */
  549.     0,
  550.     32*8, 32*8,
  551.     { 0*8, 32*8-1, 4*8, 28*8-1 },
  552.     gfxdecodeinfo,
  553.     48*16,48*16,
  554.     0,
  555.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  556.     0,
  557.     ninjakd2_vh_start,
  558.     ninjakd2_vh_stop,
  559.     ninjakd2_vh_screenrefresh,
  560.  
  561.     /* sound hardware */
  562.     0,0,0,0,
  563.     {
  564.         {
  565.             SOUND_YM2203,
  566.             &ym2203_interface
  567.         }
  568.     }
  569. };
  570.  
  571. static struct MachineDriver machine_driver_ninjak2a =
  572. {
  573.     {
  574.         {
  575.             CPU_Z80,
  576.             6000000,        /* 12000000/2 ??? */
  577.             readmem,writemem,0,0,    /* very sensitive to these settings */
  578.             ninjakd2_interrupt,1
  579.         },
  580.         {
  581.             CPU_Z80 | CPU_AUDIO_CPU,
  582.             4000000,        /* 12000000/3 ??? */
  583.             snd_readmem,snd_writemem,0,snd_writeport,
  584.             ignore_interrupt,0,
  585.         }
  586.     },
  587.     60, 10000,    /* frames per second, vblank duration */
  588.     10,
  589.     0,
  590.     32*8, 32*8,
  591.     { 0*8, 32*8-1, 4*8, 28*8-1 },
  592.     gfxdecodeinfo,
  593.     48*16,48*16,
  594.     0,
  595.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  596.     0,
  597.     ninjakd2_vh_start,
  598.     ninjakd2_vh_stop,
  599.     ninjakd2_vh_screenrefresh,
  600.  
  601.     /* sound hardware */
  602.     0,0,0,0,
  603.     {
  604.         {
  605.             SOUND_YM2203,
  606.             &ym2203_interface
  607.         },
  608.         {
  609.             SOUND_SAMPLES,
  610.             &samples_interface
  611.         },
  612.         {
  613.             SOUND_CUSTOM,    /* actually initializes the samples */
  614.             &custom_interface
  615.         }
  616.     }
  617. };
  618.  
  619.  
  620.  
  621. ROM_START( ninjakd2 )
  622.     ROM_REGION( 0x30000, REGION_CPU1 )
  623.     ROM_LOAD( "nk2_01.rom",   0x00000, 0x8000, 0x3cdbb906 )
  624.     ROM_LOAD( "nk2_02.rom",   0x10000, 0x8000, 0xb5ce9a1a )
  625.     ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, 0xad275654 )
  626.     ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, 0xe7692a77 )
  627.     ROM_LOAD( "nk2_05.rom",   0x28000, 0x8000, 0x5dac9426 )
  628.  
  629.     ROM_REGION( 0x10000, REGION_CPU2 )
  630.     ROM_LOAD( "nk2_06.rom",   0x0000, 0x10000, 0xd3a18a79 )  // sound z80 code encrypted
  631.  
  632.     ROM_REGION( 0x20000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  633.     ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, 0x41a714b3 )    /* background tiles */
  634.     ROM_CONTINUE(             0x10000, 0x4000)
  635.     ROM_CONTINUE(             0x04000, 0x4000)
  636.     ROM_CONTINUE(             0x14000, 0x4000)
  637.     ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, 0xc913c4ab )
  638.     ROM_CONTINUE(             0x18000, 0x4000)
  639.     ROM_CONTINUE(             0x0c000, 0x4000)
  640.     ROM_CONTINUE(             0x1c000, 0x4000)
  641.  
  642.     ROM_REGION( 0x20000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  643.     ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, 0x1b79c50a )    /* sprites tiles */
  644.     ROM_CONTINUE(             0x10000, 0x4000)
  645.     ROM_CONTINUE(             0x04000, 0x4000)
  646.     ROM_CONTINUE(             0x14000, 0x4000)
  647.     ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, 0x0be5cd13 )
  648.     ROM_CONTINUE(             0x18000, 0x4000)
  649.     ROM_CONTINUE(             0x0c000, 0x4000)
  650.     ROM_CONTINUE(             0x1c000, 0x4000)
  651.  
  652.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  653.     ROM_LOAD( "nk2_12.rom",   0x00000, 0x02000, 0xdb5657a9 )    /* foreground tiles */
  654.     ROM_CONTINUE(             0x04000, 0x02000)
  655.     ROM_CONTINUE(             0x02000, 0x02000)
  656.     ROM_CONTINUE(             0x06000, 0x02000)
  657.  
  658.     ROM_REGION( 0x10000, REGION_SOUND1 )
  659.     ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, 0xc1d2d170 )    /* raw pcm samples */
  660. ROM_END
  661.  
  662. ROM_START( ninjak2a )
  663.     ROM_REGION( 0x30000, REGION_CPU1 )
  664.     ROM_LOAD( "nk2_01.bin",   0x00000, 0x8000, 0xe6adca65 )
  665.     ROM_LOAD( "nk2_02.bin",   0x10000, 0x8000, 0xd9284bd1 )
  666.     ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, 0xad275654 )
  667.     ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, 0xe7692a77 )
  668.     ROM_LOAD( "nk2_05.bin",   0x28000, 0x8000, 0x960725fb )
  669.  
  670.     ROM_REGION( 2*0x10000, REGION_CPU2 )    /* 64k for code + 64k for decrypted opcodes */
  671.     ROM_LOAD( "nk2_06.bin",   0x10000, 0x8000, 0x7bfe6c9e )    /* decrypted opcodes */
  672.     ROM_CONTINUE(             0x00000, 0x8000 )                /* decrypted data */
  673.  
  674.     ROM_REGION( 0x20000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  675.     ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, 0x41a714b3 )    /* background tiles */
  676.     ROM_CONTINUE(             0x10000, 0x4000)
  677.     ROM_CONTINUE(             0x04000, 0x4000)
  678.     ROM_CONTINUE(             0x14000, 0x4000)
  679.     ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, 0xc913c4ab )
  680.     ROM_CONTINUE(             0x18000, 0x4000)
  681.     ROM_CONTINUE(             0x0c000, 0x4000)
  682.     ROM_CONTINUE(             0x1c000, 0x4000)
  683.  
  684.     ROM_REGION( 0x20000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  685.     ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, 0x1b79c50a )    /* sprites tiles */
  686.     ROM_CONTINUE(             0x10000, 0x4000)
  687.     ROM_CONTINUE(             0x04000, 0x4000)
  688.     ROM_CONTINUE(             0x14000, 0x4000)
  689.     ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, 0x0be5cd13 )
  690.     ROM_CONTINUE(             0x18000, 0x4000)
  691.     ROM_CONTINUE(             0x0c000, 0x4000)
  692.     ROM_CONTINUE(             0x1c000, 0x4000)
  693.  
  694.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  695.     ROM_LOAD( "nk2_12.rom",   0x00000, 0x02000, 0xdb5657a9 )    /* foreground tiles */
  696.     ROM_CONTINUE(             0x04000, 0x02000)
  697.     ROM_CONTINUE(             0x02000, 0x02000)
  698.     ROM_CONTINUE(             0x06000, 0x02000)
  699.  
  700.     ROM_REGION( 0x10000, REGION_SOUND1 )
  701.     ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, 0xc1d2d170 )    /* raw pcm samples */
  702. ROM_END
  703.  
  704. ROM_START( ninjak2b )
  705.     ROM_REGION( 0x30000, REGION_CPU1 )
  706.     ROM_LOAD( "1.3s",         0x00000, 0x8000, 0xcb4f4624 )
  707.     ROM_LOAD( "2.3q",         0x10000, 0x8000, 0x0ad0c100 )
  708.     ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, 0xad275654 )
  709.     ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, 0xe7692a77 )
  710.     ROM_LOAD( "nk2_05.rom",   0x28000, 0x8000, 0x5dac9426 )
  711.  
  712.     ROM_REGION( 2*0x10000, REGION_CPU2 )    /* 64k for code + 64k for decrypted opcodes */
  713.     ROM_LOAD( "nk2_06.bin",   0x10000, 0x8000, 0x7bfe6c9e )    /* decrypted opcodes */
  714.     ROM_CONTINUE(             0x00000, 0x8000 )                /* decrypted data */
  715.  
  716.     ROM_REGION( 0x20000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  717.     ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, 0x41a714b3 )    /* background tiles */
  718.     ROM_CONTINUE(             0x10000, 0x4000)
  719.     ROM_CONTINUE(             0x04000, 0x4000)
  720.     ROM_CONTINUE(             0x14000, 0x4000)
  721.     ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, 0xc913c4ab )
  722.     ROM_CONTINUE(             0x18000, 0x4000)
  723.     ROM_CONTINUE(             0x0c000, 0x4000)
  724.     ROM_CONTINUE(             0x1c000, 0x4000)
  725.  
  726.     ROM_REGION( 0x20000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  727.     ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, 0x1b79c50a )    /* sprites tiles */
  728.     ROM_CONTINUE(             0x10000, 0x4000)
  729.     ROM_CONTINUE(             0x04000, 0x4000)
  730.     ROM_CONTINUE(             0x14000, 0x4000)
  731.     ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, 0x0be5cd13 )
  732.     ROM_CONTINUE(             0x18000, 0x4000)
  733.     ROM_CONTINUE(             0x0c000, 0x4000)
  734.     ROM_CONTINUE(             0x1c000, 0x4000)
  735.  
  736.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  737.     ROM_LOAD( "nk2_12.rom",   0x00000, 0x02000, 0xdb5657a9 )    /* foreground tiles */
  738.     ROM_CONTINUE(             0x04000, 0x02000)
  739.     ROM_CONTINUE(             0x02000, 0x02000)
  740.     ROM_CONTINUE(             0x06000, 0x02000)
  741.  
  742.     ROM_REGION( 0x10000, REGION_SOUND1 )
  743.     ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, 0xc1d2d170 )    /* raw pcm samples */
  744. ROM_END
  745.  
  746. ROM_START( rdaction )
  747.     ROM_REGION( 0x30000, REGION_CPU1 )
  748.     ROM_LOAD( "1.3u",            0x00000, 0x8000, 0x5c475611 )
  749.     ROM_LOAD( "2.3s",         0x10000, 0x8000, 0xa1e23bd2 )
  750.     ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, 0xad275654 )
  751.     ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, 0xe7692a77 )
  752.     ROM_LOAD( "nk2_05.bin",   0x28000, 0x8000, 0x960725fb )
  753.  
  754.     ROM_REGION( 2*0x10000, REGION_CPU2 )    /* 64k for code + 64k for decrypted opcodes */
  755.     ROM_LOAD( "nk2_06.bin",   0x10000, 0x8000, 0x7bfe6c9e )    /* decrypted opcodes */
  756.     ROM_CONTINUE(             0x00000, 0x8000 )                /* decrypted data */
  757.  
  758.     ROM_REGION( 0x20000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  759.     ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, 0x41a714b3 )    /* background tiles */
  760.     ROM_CONTINUE(             0x10000, 0x4000)
  761.     ROM_CONTINUE(             0x04000, 0x4000)
  762.     ROM_CONTINUE(             0x14000, 0x4000)
  763.     ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, 0xc913c4ab )
  764.     ROM_CONTINUE(             0x18000, 0x4000)
  765.     ROM_CONTINUE(             0x0c000, 0x4000)
  766.     ROM_CONTINUE(             0x1c000, 0x4000)
  767.  
  768.     ROM_REGION( 0x20000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  769.     ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, 0x1b79c50a )    /* sprites tiles */
  770.     ROM_CONTINUE(             0x10000, 0x4000)
  771.     ROM_CONTINUE(             0x04000, 0x4000)
  772.     ROM_CONTINUE(             0x14000, 0x4000)
  773.     ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, 0x0be5cd13 )
  774.     ROM_CONTINUE(             0x18000, 0x4000)
  775.     ROM_CONTINUE(             0x0c000, 0x4000)
  776.     ROM_CONTINUE(             0x1c000, 0x4000)
  777.  
  778.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  779.     ROM_LOAD( "12.5n",        0x00000, 0x02000, 0x0936b365 )    /* foreground tiles */
  780.     ROM_CONTINUE(             0x04000, 0x02000)
  781.     ROM_CONTINUE(             0x02000, 0x02000)
  782.     ROM_CONTINUE(             0x06000, 0x02000)
  783.  
  784.     ROM_REGION( 0x10000, REGION_SOUND1 )
  785.     ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, 0xc1d2d170 )    /* raw pcm samples */
  786. ROM_END
  787.  
  788.  
  789.  
  790. void init_ninjak2a(void)
  791. {
  792.     unsigned char *rom = memory_region(REGION_CPU2);
  793.     int diff = memory_region_length(REGION_CPU2) / 2;
  794.  
  795.     memory_set_opcode_base(1,rom+diff);
  796. }
  797.  
  798.  
  799.  
  800. GAMEX(1987, ninjakd2, 0,        ninjakd2, ninjakd2, 0,        ROT0, "UPL", "Ninja Kid II (set 1)", GAME_NO_SOUND )    /* sound program is encrypted */
  801. GAME( 1987, ninjak2a, ninjakd2, ninjak2a, ninjakd2, ninjak2a, ROT0, "UPL", "Ninja Kid II (set 2)" )
  802. GAME( 1987, ninjak2b, ninjakd2, ninjak2a, ninjakd2, ninjak2a, ROT0, "UPL", "Ninja Kid II (set 3)" )
  803. GAME( 1987, rdaction, ninjakd2, ninjak2a, ninjakd2, ninjak2a, ROT0, "UPL (World Games license)", "Rad Action" )
  804.